/*
 * Kelas Point
 */
package Point;

/**
 * Kelas Point
 * @author SAM
 */

public class Point {
    
    private double absis, ordinat;
    /**
     * Konstruktor
     */
    public Point(){
        absis = 0;
        ordinat = 0;
    }
    
    /**
     * Konstruktor dengan parameter
     * @param _x Absis
     * @param _y Ordinat
     */
    public Point(double _x, double _y){
        absis = _x;
        ordinat = _y;
    }
    /**
     * Gettter Absis
     * @return Absis
     */
    public double getAbsis(){
        return absis;
    }
    
    /**
     * Getter Ordinat
     * @return Ordinat
     */
    public double getOrdinat(){
        return ordinat;
    }
    
    /**
     * Add Point _p ke self
     * @param _p Suatu point
     */
    public void Add(Point _p){
        absis += _p.absis;
        ordinat += _p.ordinat;
    }
    
    /**
     * Add absis ke self
     * @param _x absis
     */
    public void AddAbsis(double _x){
        absis += _x;
    }
    
    /**
     * Add ordinat ke self
     * @param _y ordinat
     */
    public void AddOrdinat(double _y){
        ordinat += _y;
    }
    
    /**
     * Mengembalikan point dalam format (x,y)
     * @return Point String
     */
    public String toString(){
        return "("+absis+","+ordinat+")";
    }
    
    /**
     * Mengecek apakah sebuah object bernilai sama dengan object sekarang 
     * Override dari Object.equals
     * @param obj
     * @return boolean, hasil perbandingan
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (obj == null) {
            return false;
        } else if (obj.getClass() != getClass()) {
            return false;
        }
        
        final Point other = (Point)obj;
        if (other.getOrdinat() != getOrdinat()) return false;
        if (other.getAbsis() != getAbsis()) return false;
        return true;
    }

    /**
     * Mengembalikan hasil hashing dari Object
     * @return integer (angka hash) 
     */
    public int hashCode() {
        int hash = 7;
        hash = 71 * hash + (int) (Double.doubleToLongBits(this.absis) ^ (Double.doubleToLongBits(this.absis) >>> 32));
        hash = 71 * hash + (int) (Double.doubleToLongBits(this.ordinat) ^ (Double.doubleToLongBits(this.ordinat) >>> 32));
        return hash;
    }
}
